import request from '#/utils/requestAbort';

const apiPre = '/tianji-transaction/rollingBatch';

/**
 * 获取序列列表信息
 * @param {String} date 查询日期
 * @returns
 */
export const fetchSequences = async (date) => {
  return request(`${apiPre}/fetchSequences/${date}`);
};

/**
 * 获取未开始申报的序列信息
 */
export const fetchSequencesFuture = async () => {
  return request(`${apiPre}/fetchFutureTradeDate`);
};

/**
 * 获取交易序列限价信息
 * @param {String} menuCode  菜单编码
 * @param {String} sequenceId  序列id
 * @returns
 */
export const fetchSequencesLimit = async (sequenceId) => {
  return request(`${apiPre}/fetchPriceLimitAll/${sequenceId}`);
};

/**
 * 获取序列下的方案信息
 * @param {String} sequenceId  序列id
 * @returns
 */
export const fetchPrograms = async (sequenceId) => {
  return request(`${apiPre}/fetchProgramAll/${sequenceId}`);
};

/**
 * 获取方案下的时段信息
 * @param {String} menuCode 菜单编码
 * @param {String} programId 方案id
 * @returns
 */
export const fetchHourOrderInfo = async (menuCode, programId) => {
  return request(`${apiPre}/fetchProgramDetail/${menuCode}/${programId}`);
};

/**
 * 获取序列下交易单元的状态
 * @param {*} menuCode
 * @param {*} sequenceId
 * @returns
 */
export const fetchUnitStatus = async (menuCode, sequenceId) => {
  return request(`${apiPre}/fetchUnitStatusInfo/${menuCode}/${sequenceId}`);
};

/**
 * 获取带申报方案总览
 * @param {*} menuCode
 * @param {*} sequenceId
 * @returns
 */
export const fetchOverviewProgramToBeSubmited = async (menuCode, sequenceId) => {
  return request(`${apiPre}/fetchUnitSubmitInfos/${menuCode}/${sequenceId}`);
};

/**
 * 获取已经被占用的场站id
 * @param {*} sequenceId
 * @returns
 */
export const fetchUsedUnit = async (sequenceId) => {
  return request(`${apiPre}/fetchUsedUnit/${sequenceId}`);
};

/**
 * 保存交易单元
 * @param {*} menuCode
 * @param {*} programTitle
 * @param {*} sequenceId
 * @param {*} unitIdList
 * @param {*} programId
 */
export const saveUnits = async (menuCode, programTitle, sequenceId, unitIdList, programId) => {
  return request(`${apiPre}/saveUnits`, {
    method: 'POST',
    data: { menuCode, programTitle, sequenceId, unitIdList, programId },
  });
};

/**
 * 获取方案的最新日志
 * @param {*} programId
 */
export const fetchLatestLog = async (programId) => {
  return request(`${apiPre}/fetchProgramLatestLog/${programId}`);
};

/**
 * 删除方案
 * @param {*} menuCode
 * @param {*} programId
 * @returns
 */
export const deleteProgram = async (menuCode, programId) => {
  return request(`${apiPre}/deleteProgram`, {
    method: 'POST',
    data: { menuCode, programId },
  });
};

/**
 * 提交方案
 * @param {*} intervals 时段信息
 * @param {*} menuCode 菜单编码
 * @param {*} operateType 操作类型 0-保存,1-定时申报,2-立即申报
 * @param {*} programId  方案id
 * @param {*} sequenceId 序列id
 * @param {*} timelySubmitTime 定时时间
 * @returns
 */
export const submit = async (
  intervals,
  menuCode,
  operateType,
  programId,
  sequenceId,
  timelySubmitTime,
  adjust,
) => {
  return request(`${apiPre}/submitProgram`, {
    method: 'POST',
    data: { intervals, menuCode, operateType, programId, sequenceId, timelySubmitTime, adjust },
  });
};

/**
 * 取消定时
 * @param {*} menuCode
 * @param {*} programId
 * @returns
 */
export const cancelTimelySubmit = async (menuCode, programId) => {
  return request(`${apiPre}/cancelTimelySubmit`, {
    method: 'POST',
    data: { menuCode, programId },
  });
};

/**
 * 异步更新交易单元状态
 * @param {*} menuCode 菜单编码
 * @param {*} sequenceId  序列id
 */
export const updateStatus = async (menuCode, sequenceId) => {
  return request(`${apiPre}/asyncUpdateUnitStatusInfo`, {
    method: 'POST',
    data: { menuCode, sequenceId },
  });
};

/**
 * 获取带申报方案总览
 * @param {*} menuCode  菜单编码
 * @param {*} sequenceId  序列id
 * @returns
 */
export const fetchUnitSubmitInfos = (menuCode, sequenceId) => {
  return request(`${apiPre}/fetchUnitSubmitInfos/${menuCode}/${sequenceId}`);
};

export const fetchOperateLogs = async (programId) => {
  // 获取操作日志列表
  return request(`${apiPre}/fetchOperateLogs/${programId}`);
};

export const exportProgram = async (programId) => {
  // 导出方案申报信息,导出类型,目前只支持传excel
  let type = 'excel';
  return request(`${apiPre}/exportProgram`, {
    method: 'POST',
    data: { programId, type },
    responseType: 'blob',
    getResponse: true,
  });
};

export async function fetchTradeTime() {
  // 获取当前交易中心的当前时间
  return request(`/tianji-transaction/tradeTime/fetchTradeTime`);
}

// 省份-交易中心-场站（数据权限）
export async function queryMarketList(menuCode) {
  return request(`/power/dataPower/common/${menuCode}/t_station`, {
    method: 'GET',
  });
}
